<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/index3.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-1.8.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/My97DatePicker/WdatePicker.js"></script>
</head>

<body>
<form action="add" method="post">
    制单人工号:
    <input type="text" name="users.uid" value="${user.uid}">
    制单人:
    <input type="text" name="users.uname" value="${user.uname}"><br>
    商品归属:
    <input type="text" name="garea"><br>
    商品编号:
    <input type="text" name="gnum"><br>
    商品名称:
    <input type="text" name="gname"><br>
    类型:
    <select name="Type.tid" id="tt">
     <option value=""></option>
    </select>
    品牌:
    <select name="brand.bid" id="bb">
        <option value=""></option>
    </select><br>
    图片:
    <input type="hidden" name="img" id="imgname">
    <img src="" width="50px" height="50px" id="img">
    <input type="file" onchange="photo(this)"><br>
    型号:<input type="text" name="gxing"><br>
    规格:<input type="text" name="ggui"><br>
    单价:<input type="text" name="price"><br>
    <input type="button" value="增加" onclick="tj()">
</form>
<script>
    function photo(obj) {
     var len=obj.files[0].size;
     if(len>0&&len<5*1024*1024){
       var formdate= new FormData();
       formdate.append("file",obj.files[0]);
       $.ajax({
           url:"photo",
           type:"post",
            data:formdate,
            contentType:false,
            processData:false,
           success:function (thiz) {
            $("#imgname").val(thiz);
            $("#img").prop("src","/pic/"+thiz);
           }
       });
     }
    }
$.post("typelist",function (obj) {
    for(var w of obj){
        $("#tt").append('<option value="'+w.tid+'">'+w.tname+'</option>')
    }
},"json")

    $.post("brandlist",function (obj) {
        for(var w of obj){
            $("#bb").append('<option value="'+w.bid+'">'+w.bname+'</option>')
        }
    },"json")

    function tj() {
     var price= $('[name="price"]').val();
     var zz=/^\d+(\.\d{1,2})?$/;
     if(zz.test(price)){
         $('form').submit();
     }else {
         alert("价格不符合规范");
     }
    }
</script>
</body>
</html>
